﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace lcs.Web.project
{
    public partial class upfile : System.Web.UI.Page
    {
        BLL.out_storage_detail bll = new BLL.out_storage_detail();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
                {
                    int out_storage_detail_Id = 0;
                    int.TryParse(Request.Params["id"].Trim(), out out_storage_detail_Id);
                    if (out_storage_detail_Id > 0)
                    {
                        Model.out_storage_detail model = bll.GetModel(out_storage_detail_Id);
                        if (!string.IsNullOrEmpty(model.ofile))
                        {
                            HyperLink1.Visible = true;
                            HyperLink1.NavigateUrl = model.ofile;
                        }
                    }
                    else
                    {
                        Maticsoft.Common.MessageBox.Show(this, "参数错误！");
                    }
                }
            }
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
            {
                int out_storage_detail_Id = 0;
                int.TryParse(Request.Params["id"].ToString(), out out_storage_detail_Id);
                if (FileUpload1.HasFile)
                {
                    string fileExrensio = System.IO.Path.GetExtension(FileUpload1.FileName).ToLower();//ToLower转化为小写
                    string FileType = FileUpload1.PostedFile.ContentType;
                    string UploadURL = Server.MapPath("~/upload/");//上传的目录
                    string filename = DateTime.Now.ToString("yyyyMMddHHmmssfff");
                    if (fileExrensio == ".rar" || fileExrensio == ".zip")//判断文件类型
                    {

                        try
                        {
                            if (!System.IO.Directory.Exists(UploadURL))//判断文件夹是否已经存在
                            {
                                System.IO.Directory.CreateDirectory(UploadURL);//创建文件夹
                            }

                            FileUpload1.PostedFile.SaveAs(UploadURL + filename + fileExrensio);
                            bll.UpdatePic(out_storage_detail_Id, "/upload/" + filename + fileExrensio);
                            HyperLink1.Visible = true;
                            HyperLink1.NavigateUrl = "/upload/" + filename + fileExrensio;
                        }
                        catch
                        {
                            ;
                        }
                    }
                    else
                    {
                        Maticsoft.Common.MessageBox.Show(this, "只能上传rar或zip格式");
                        return;
                    }
                }

            }


        }

        protected void btnDel_Click(object sender, EventArgs e)
        {
            if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
            {
                int out_storage_detail_Id = 0;
                int.TryParse(Request.Params["id"].ToString(), out out_storage_detail_Id);
                bll.UpdatePic(out_storage_detail_Id, "");
                HyperLink1.Visible = false;
            }

        }
    }

}